/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.HashMap;
import java.util.Map;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import constant.ColumnEnum;
import util.GradeExcelReader;

/**
 *
 * @author 乐山
 */
public class Main {
    public static void main(String[] args) {
        /**
         * 学号->person
         */
        Map<String, Person> persons = new HashMap<>();
        String fileName = "d:/temp/grades.xls";
        Workbook wb = GradeExcelReader.readWorkbookFromExcelFile(fileName);
        Sheet sheet0 = wb.getSheetAt(0);
        
        Row row = null;
        for (int i = 1; i < sheet0.getLastRowNum(); i++) {
            row = sheet0.getRow(i);
            //读取学生
            Cell idCell = row.getCell(ColumnEnum.ID.getColumn());
            Cell nameCell = row.getCell(ColumnEnum.NAME.getColumn());
            Cell clazzCell = row.getCell(ColumnEnum.CLAZZ.getColumn());
            String id = idCell.getStringCellValue();
            String name = nameCell.getStringCellValue();
            String clazz = clazzCell.getStringCellValue();
            //读取成绩
            Cell courseNameCell = row.getCell(ColumnEnum.COURSENAME.getColumn());
            Cell typeCell = row.getCell(ColumnEnum.TYPE.getColumn());//修习类别
            Cell creditCell = row.getCell(ColumnEnum.CREDIT.getColumn());//学分
            Cell examStatCell = row.getCell(ColumnEnum.EXAMSTAT.getColumn());//考试性质
            Cell finaCell = row.getCell(ColumnEnum.FINALGRADE.getColumn());
            String cName = courseNameCell.getStringCellValue();
            String type = typeCell.getStringCellValue();
            Double credit = Double.valueOf(creditCell.getStringCellValue());
            String examStat = examStatCell.getStringCellValue();
            Integer finalGrade = Integer.valueOf(finaCell.getStringCellValue());
            
            CourseGrade courseGrade = new CourseGrade(cName, type, examStat, credit, finalGrade);
            
            if (!persons.containsKey(id)){
                Person person = new Person(id,name, clazz);
                persons.put(id, person);
                person.putGrade(courseGrade);
            }else{
                persons.get(id).putGrade(courseGrade);
            }
        }
        /*for (Map.Entry<String, Person> e : persons.entrySet()) {
        System.out.println("id="+e.getKey()+" Person="+e.getValue());
        }*/
        //Person p = persons.get("201721123023");//
        Person p = persons.get("201721123122");//不及格较多

        System.out.println(p);
        System.out.println("基础选修="+p.getGrade().calcBasicECCredit());
        System.out.println("专业选修="+p.getGrade().calcSpecialECCredit());
        System.out.println("专业必修="+p.getGrade().calcSpeicalRCCredit());
    }
    
}
